﻿<UserControl x:Class="Samba.Modules.SettingsModule.RuleActionView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:SettingsModule="clr-namespace:Samba.Modules.SettingsModule" xmlns:UIControls="clr-namespace:UIControls;assembly=UIControls" mc:Ignorable="d" d:DesignHeight="300"
     d:DesignWidth="300">
    <UserControl.Resources>
        <DataTemplate x:Key="comboTemplate">
            <StackPanel Margin="5,3,0,0" Orientation="Horizontal">
                <TextBlock Text="{Binding NameDisplay}" Margin="0,0,5,0" MinWidth="120"/>
                <ComboBox IsEditable="True" ItemsSource="{Binding Values}" Text="{Binding Value}" HorizontalAlignment="Left" MinWidth="150"/>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="textTemplate">
            <StackPanel Margin="5,3,0,0" Orientation="Horizontal">
                <TextBlock Text="{Binding NameDisplay}" Margin="0,0,5,0" MinWidth="120"/>
                <TextBox Text="{Binding Value}" HorizontalAlignment="Left" MinWidth="150"/>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="passwordTemplate">
            <StackPanel Margin="5,3,0,0" Orientation="Horizontal">
                <TextBlock Text="{Binding NameDisplay}" Margin="0,0,5,0" MinWidth="120"/>
                <UIControls:BindablePasswordBox Password="{Binding Value}" HorizontalAlignment="Left" MinWidth="150"/>
            </StackPanel>
        </DataTemplate>

        <SettingsModule:PropertyEditorTemplateSelector x:Key="propertyTemplateSelector" 
            TextTemplate="{StaticResource textTemplate}"
            ValueTemplate="{StaticResource comboTemplate}"
            PasswordTemplate="{StaticResource passwordTemplate}"/>

    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto">
            <StackPanel>
                <Label HorizontalAlignment="Left" Content="{LocText ActionName, Suffix=':'}" />
                <TextBox HorizontalAlignment="Left" MinWidth="200" Text="{Binding Name}" />
                <Label HorizontalAlignment="Left" Content="{LocText ActionType, Suffix=':'}" />
                <ComboBox HorizontalAlignment="Left" MinWidth="200" SelectedValue="{Binding SelectedActionType}"
                 ItemsSource="{Binding ActionTypes}" SelectedValuePath="ActionType" DisplayMemberPath="ActionName" />

                <Label Visibility="{Binding IsParameterLabelVisible,Converter={StaticResource VisibilityConverter},FallbackValue=Collapsed}"
                   HorizontalAlignment="Left" Content="{LocText Parameters, Suffix=':'}" />

                <ItemsControl ItemsSource="{Binding ParameterValues}" 
                              ItemTemplateSelector="{StaticResource propertyTemplateSelector}"/>

            </StackPanel>
        </ScrollViewer>
        <StackPanel Grid.Row="1">
            <Button HorizontalAlignment="Left" Margin="0,10,3,0" MinWidth="70" Content="{Binding SaveCommand.Caption}"
                 Command="{Binding SaveCommand}" />
            <Label Content="{Binding Error}" Foreground="Red" />
        </StackPanel>
    </Grid>
</UserControl>